package org.ciallo.easytokencore.spring;

import org.ciallo.easytokencore.annotation.handler.EasyAnnotationHandlerInterface;
import org.ciallo.easytokencore.strategy.EasyAnnotationStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Easy-Token 核心Bean注入器
 *
 * <p>核心功能：</p>
 * <ul>
 *   <li>自动收集所有实现了EasyAnnotationHandlerInterface的Bean</li>
 *   <li>将处理器自动注册到EasyAnnotationStrategy</li>
 *   <li>支持可选依赖(required=false)</li>
 * </ul>
 *
 * <p>工作原理：</p>
 * <ol>
 *   <li>Spring启动时自动调用setEasyAnnotationHandler方法</li>
 *   <li>收集所有EasyAnnotationHandlerInterface实现类</li>
 *   <li>注册到策略管理器的全局实例</li>
 * </ol>
 *
 * <p>使用示例：</p>
 * <pre>
 * {@code
 * // 自定义注解处理器
 * @Component
 * public class MyHandler implements EasyAnnotationHandlerInterface {
 *     // 实现处理方法
 * }
 *
 * // 自动注册到EasyAnnotationStrategy
 * }
 * </pre>
 *
 * @Description: Easy-Token 核心Bean注入器
 * @Author: Jukomu
 * @Package: org.ciallo.easytokencore.spring
 * @Project: easy-token-demo
 * @Version: 1.0.0
 * @name: EasyBeanInject
 * @Date: 2025/5/6-22:29
 * @Filename: EasyBeanInject
 * @see EasyAnnotationHandlerInterface
 * @see EasyAnnotationStrategy
 */
@Component
public class EasyBeanInject {

    @Autowired(required = false)
    public void setEasyAnnotationHandler(List<EasyAnnotationHandlerInterface<?>> handlerList) {
        for (EasyAnnotationHandlerInterface<?> handler : handlerList) {
            EasyAnnotationStrategy.instance.registerAnnotationHandler(handler);
        }
    }
}
